/**
 * \file vmware.h
 * \brief VMware support
 * \author Corey Tabaka
 */

/*
   Copyright 2005 Corey Tabaka

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/

#ifndef __KERNEL_VMWARE_H__
#define __KERNEL_VMWARE_H__

#include <ktypes.h>

#define VMWARE_MAGIC        0x564D5868      /* Backdoor magic number        */
#define VMWARE_PORT         0x5658          /* Backdoor port number         */

#define VMCMD_APM_FUNCTION  0x02            /* APM function?                */
#define VMCMD_GET_CURSOR    0x04            /* Get cursor position          */
#define VMCMD_SET_CURSOR    0x05            /* Set cursor position          */
#define VMCMD_GET_CLIPLEN   0x06            /* host->guest copy length      */
#define VMCMD_GET_CLIPDATA  0x07            /* host->guest copy data        */
#define VMCMD_SET_CLIPLEN   0x08            /* guest->host copy length      */
#define VMCMD_SET_CLIPDATA  0x09            /* guest->host copy date        */
#define VMCMD_GET_VERSION   0x0a            /* Get version number           */
#define VMCMD_GET_DEVICE    0x0b            /* Get device information       */
#define VMCMD_SET_DEVICE    0x0c            /* Set device state             */
#define VMCMD_GET_SETTING   0x0d            /* Get preference settings      */
#define VMCMD_SET_SETTING   0x0e            /* Set Preference settings      */
#define VMCMD_GET_HOSTRES   0x0f            /* Get host's screen size       */
#define VMCMD_POPUP_DIALOG  0x12            /* OS not found message popup   */
#define VMCMD_GET_VMCONFIG  0x14            /* Get VM config information    */
#define VMCMD_GET_TIME      0x17            /* Get host's time (GMT)        */
#define VMCMD_TRANSFER      0x1e            /* Generic data transfer        */

/*
 *  Preference bitmask (for VMCMD_GET_SETTING, VMCMD_SET_SETTING)
 */
#define VMPREF_GRAB_MOVE    0x0001          /* grab by cursor movement      */
#define VMPREF_UNGRAB_MOVE  0x0002          /* ungrab by cursor movement    */
#define VMPREF_SCROLL_MOVE  0x0004          /* scroll by cursor movement    */
#define VMPREF_COPY_PASTE   0x0010          /* copy and paste               */
#define VMPREF_FULLSCREEN   0x0040          /* full screen (read only)      */
#define VMPREF_ENTER_FULL   0x0080          /* full screen (write only)     */
#define VMPREF_SYNCRONIZE   0x0400          /* time syncronization          */

#define VMCLIP_MAX_LENGTH   65355           /* maximum copy & paste length  */

extern inline void vm_cmd(uint32 *p) {
	__asm__  ("in %%dx, %%eax"
	: "=a"(p[0]), "=b"(p[1]), "=c"(p[2]), "=d"(p[3])
	: "a"(p[0]), "b"(p[1]), "c"(p[2]), "d"(p[3])
	);
}

extern bool inVMware;

void vmware_init(void);

#endif
